package spr;

import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import spr.test.RobotTestBed;
import static org.junit.Assert.assertTrue;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that RastaBot encounters
 * every corner counter-clockwise.
 * 
 * @author Shaun Ramento
 */
public class TestCornerMovement extends RobotTestBed {

  boolean topLeft = false;
  boolean topRight = false;
  boolean bottomLeft = false;
  boolean bottomRight = false;

  /**
   * Specifies that SittingDuck and RastaBot are to be matched up in this test case. *
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,spr.RastaBot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Test to make sure that the robot moves to all to the corners counter-clockwise.
   * 
   * @param event TurnEndedEvent
   */

  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double getWidthLocation = robot.getX();
    double getHeightLocation = robot.getY();
    if ((getWidthLocation == 18.0) && (getHeightLocation == 582.0)) {
      topLeft = true;
    }
    else if ((getWidthLocation == 782.0) && (getHeightLocation == 582.0)) {
      topRight = true;
    }
    else if ((getWidthLocation == 18.0) && (getHeightLocation == 18.0)) {
      bottomLeft = true;
    }
    if ((getWidthLocation == 782.0) && (getHeightLocation == 18.0)) {
      bottomRight = true;
    }
    System.out.println(getWidthLocation + ", " + getHeightLocation);
  }
  /**
   * Test to make sure that the robot reaches every corner.
   * @param event BattleCompletedEvent
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Robot has moved along top left corner.", topLeft);
    assertTrue("Robot has moved along top right corner.", topRight);
    assertTrue("Robot has moved along bottom right corner.", bottomLeft);
    assertTrue("Robot has moved along bottom left corner.", bottomRight);
  }
}
